package com.example.tx.service.impl;


import com.alibaba.dubbo.config.annotation.Reference;
import io.shardingsphere.transaction.annotation.ShardingTransactionType;
import io.shardingsphere.transaction.api.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tx.pojo.Address;
import com.example.tx.mapper.AddressMapper;
import com.example.tx.service.AddressService;
import org.springframework.transaction.annotation.Transactional;
import service.TxService;

/**
 * @author cyt
 * @create 2021-03-21 9:14
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {
    @Reference
    private TxService userService;

    @Autowired
    private  AddressMapper addressMapper;

    @Transactional(rollbackFor = Exception.class)
    @ShardingTransactionType(TransactionType.XA)
    @Override
    public String testTx() {
        // rpc 服务
        String s = userService.testTx(2);

        int a = 1 / 0;
        // 本地服务
        Address address = addressMapper.selectById(2);
        address.setAddress("sharding jdbc");
        addressMapper.insert(address);
        return s + "ok";
    }
}
